//导入reques.js请求工具
import request from '@/utils/request.js'

//提供调用注册接口的函数
export const userRegisterService = (registerData) => {//registerData: username password
    //request.post(路径，参数),直接写registerData发送的时json格式的数据
    //而实际应该是 x-www-form-urlencoded格式
    //借助 UrlSeacherParams完成传递 
    const params = new URLSearchParams()//创建 URLSearchParams 实例

    for (let key in registerData) {//通过遍历registerData对象的所有键值对，使用append方法将它们添加到params实例中
        params.append(key, registerData[key]);
    }

    // request.post('/user/register', registerData)
    return request.post('/user/register', params)

}

//提供调用登录接口的函数
export const userLoginService = (loginData) => {
    const params = new URLSearchParams();
    for (let key in loginData) {
        params.append(key, loginData[key])
    }
    return request.post('/user/login', params)
}

//获取用户详细信息
export const userInfoService = () => {
    return request.get('/user/userInfo')
}

//修改个人信息 
export const userInfoUpdateService = (userInfoData) => {
    return request.put('/user/update', userInfoData)
}

//更新头像,queryString
export const userAvatarUpdateService = (avatarUrl) => {
    const params = new URLSearchParams();
    params.append('avatarUrl', avatarUrl)
    return request.patch('/user/updateAvatar', params)
}

//重置密码
export const userUpdatePasswordService = (updateData) => {
    return request.patch('/user/updatePwd', updateData)
}